﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model  IEnumerable<Domain.Dto.MvcControllerDto>
@{
    ViewBag.subtitle = "控制器管理";
    ViewBag.title = "控制器管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{Html.Telerik().Grid(Model)
    .Name("ControllerGrid")
    .ToolBar(toolBar => toolBar.Template(
    @<text>
    @{
        if (Html.HasUiPermission(this.ViewContext, "searchcontroller"))
        { 
        <label class="customer-label" for="Customers-input">
            控制器描述:
        </label>
        <input type="text" id="searchController" value="控制器描述" data-autocomplete="/permission/searchcontroller" />
        <input type='button' value='我要搜索' class='t-button' onclick='searchChange()' />
        }
    }
    <a href='/permission/' style="float: right;" class='t-button'>返回权限列表</a> <a href="/permission/controllerclass/"
        style="float: right;" class="t-button">控制器分类列表</a>
    </text>))
    .Columns(columns =>
    {
        columns.Bound(o => o.Id).Width(50).Title("系统Id").Hidden();

        columns.Template(@<text><a href = '/permission/controllerinfo/@(item.Id)'>@(item.AssemblyFullName)</a></text>)
        .ClientTemplate("<a href='/permission/controllerinfo/<#=Id#>'><#= AssemblyFullName #></a>")
        .Width(200).Title("控制器系统名");

        columns.Bound(o => o.Name).Width(300).Title("控制器名").Hidden();
        columns.Bound(o => o.Remark).Width(300).Title("控制器描述");
        columns.Bound(o => o.IpAddress).Width(100).Title("添加IP").ReadOnly();
        columns.Bound(o => o.AddTime).Format("{0:yyyy-MM-dd HH:mm:ss}").Width(100).Title("添加时间").ReadOnly();
        columns.Bound(o => o.SortNum).Width(100).Title("排序号").Hidden();
        columns.Bound(o => o.State).Width(100).Title("状态").Hidden();

    })
    .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding").OnComplete("bindComplete"))
    .DataKeys(key => key.Add("Id"))//添加主键
    .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxcontrollerlist", "permission"))
    .Pageable(page => page.PageSize(15))
    .Render();
}
<script type="text/javascript">
    function searchChange() {
        $("#ControllerGrid").data("tGrid").rebind();
    }

    function dataBinding(args) {
        var searchKeyStr = $("#searchController").val();
        if (searchKeyStr == '控制器描述') {
            searchKeyStr = '';
        }
        args.data = $.extend(args.data, { searchKey: searchKeyStr });
    }

    function bindComplete(e) {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        var success = e.response.success;
        if (success != null && success != undefined) {
            alert(e.response.message);
            window.location.reload();
        }
    }

    $(function () {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        $(":input[data-autocomplete]").each(function () {
            $(this).autocomplete({
                source: $(this).attr("data-autocomplete")
            }
            );
        });
        $("#searchController").focus(function () {
            if (this.value == "控制器描述") {
                $("#searchController").val("");
            }
        }).blur(function () {
            if (this.value == "") {
                $("#searchController").val("控制器描述");
            }
        });
    });
</script>
